package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import io.renren.common.utils.R;
import io.renren.datasource.annotation.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.ZbbUserDao;
import io.renren.modules.generator.entity.ZbbUserEntity;
import io.renren.modules.generator.service.ZbbUserService;


@Service("zbbUserService")
@DataSource("slave1")
public class ZbbUserServiceImpl extends ServiceImpl<ZbbUserDao, ZbbUserEntity> implements ZbbUserService {
    @Autowired
    ZbbUserDao zbbUserDao;
    @DataSource("slave1")
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ZbbUserEntity> page = this.page(
                new Query<ZbbUserEntity>().getPage(params),
                new QueryWrapper<ZbbUserEntity>()
        );

        return new PageUtils(page);
    }

    @DataSource("slave1")
    @Override
    public ZbbUserEntity getById(String id) {
        ZbbUserEntity zbbUserEntity = zbbUserDao.selectById(id);
        return zbbUserEntity;
    }

    @Override
    public boolean save(ZbbUserEntity entity) {
        return SqlHelper.retBool(zbbUserDao.insert(entity));
    }


    @DataSource("slave1")
    @Override
    public boolean updateById(ZbbUserEntity user) {

        return SqlHelper.retBool(zbbUserDao.updateById(user));
    }

    @DataSource("slave1")
    @Override
    public boolean removeByIds(List idList) {
        return CollectionUtils.isEmpty(idList) ? false : SqlHelper.retBool(zbbUserDao.deleteBatchIds(idList));
    }

}